//
//  StatusCellHeadView.swift
//  Weibo10
//
//  Created by Leon on 15/10/19.
//  Copyright © 2015年 Leon. All rights reserved.
//

import UIKit

let sepLineViewHeight = 4 * scale
class StatusCellHeadView: UIView {
    
    /// 微博视图模型
    var viewsModel:StatusViewModel? {
        didSet{
            
            // 微博名字
            nameLable.text = viewsModel?.status.user?.screen_name
            
            // TODO: - 时间，来源
            timeLabel.text = "fovever"
            sourceLabel.text = "来源:来自星星的你"
            
            // 微博头像
            iconView.sd_setImageWithURL(viewsModel?.userProfileURL, placeholderImage: viewsModel?.placeholder)
            // VIP图标
            vipIconView.image = viewsModel?.userVIPIconView
            // 认证图标
            memberIconView.image = viewsModel?.userMemberIconView
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    /// 微博头像
    private lazy var iconView: UIImageView = UIImageView(imageName: "avatar_default_big")
    /// 微博名字
    private lazy var nameLable: UILabel = UILabel(title: "练爱女孩", fontSize: 15)
    /// VIP图标
    private lazy var vipIconView: UIImageView = UIImageView(imageName: "common_icon_membership")
    /// 认证图标
    private lazy var memberIconView: UIImageView = UIImageView(imageName: "avatar_grassroot")
    /// 时间图标
    private lazy var timeLabel: UILabel = UILabel(title: "刚刚", color: UIColor.orangeColor(), fontSize: 11)
    /// 来源信息
    private lazy var sourceLabel: UILabel = UILabel(title: "来源:来自星星的你", fontSize: 11)
    //
    private lazy var sepLineView: UIView = {
        let v = UIView()
        v.backgroundColor = UIColor(white: 0.95, alpha: 1)
        return v
    }()

}

extension StatusCellHeadView {
    
    func setupUI() {
        // 1 添加控件
        addSubview(sepLineView)
        addSubview(iconView)
        addSubview(nameLable)
        addSubview(vipIconView)
        addSubview(memberIconView)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        
        // 2 自动布局
        sepLineView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self.snp_top)
            make.left.equalTo(self.snp_left)
            make.width.equalTo(self.snp_width)
            make.height.equalTo(sepLineViewHeight)
        }
        
        iconView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(sepLineView.snp_bottom).offset(statusCellMargin)
            make.left.equalTo(self.snp_left).offset(statusCellMargin)
            make.width.equalTo(statusHeadIconViewWidth)
            make.height.equalTo(statusHeadIconViewWidth)
        }
        
        nameLable.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(iconView.snp_top)
            make.left.equalTo(iconView.snp_right).offset(statusCellMargin)
        }
        
        vipIconView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(nameLable.snp_top)
            make.left.equalTo(nameLable.snp_right).offset(statusCellMargin)
        }
        
        memberIconView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(iconView.snp_right)
            make.centerY.equalTo(iconView.snp_bottom)
        }
        
        timeLabel.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(iconView.snp_bottom)
            make.left.equalTo(iconView.snp_right).offset(statusCellMargin)
        }
        
        sourceLabel.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(iconView.snp_bottom)
            make.left.equalTo(timeLabel.snp_right).offset(statusCellMargin)
        }
    }
}







